<?php

namespace App\Http\Controllers\Home;

use App\Models\Comment;
use App\Models\Doctor;
use App\Models\Worktime;

class DoctorController extends BaseController
{

    public function __construct(Comment $comment, Doctor $doctor, Worktime $worktime)
    {
        parent::__construct();
        $this->doctor = $doctor;
        $this->worktime = $worktime;
        $this->comment = $comment;
    }

    // 获取首页数据
    public function getDoctorInfo()
    {
        $doctor_info = $this->doctor->getDoctorByInfo(request());
        $data['doctor_info'] = $doctor_info;
        $comment = $this->comment->getCommentListById($doctor_info['data']['id']);
        $data['comment'] = $comment;
        $data['askurl'] ='';
        if ($doctor_info['data']['customer_service']) {
            $param['kfid'] = $doctor_info['data']['customer_service'];
            $param['uid'] = request('mid');
            $url = apiCurl('askurl',$param,'http://155m5k1578.iask.in:30552/askapi/?service=Index');
            $data['askurl'] = $url['data']['url'];
        }
        return ajax_return($data);
    }

    // 获取医师工作时间段
    public function getDoctorWorkTime()
    {
        $doctor_info = $this->doctor->getDoctorById(request());
        $request['id'] = $doctor_info['data']['id'];
        $request['key'] = request('key');
        $request['mid'] = request('mid');
        $work_time = $this->worktime->getWorkTimeById($request);
        $data['doctor'] = $doctor_info;
        $data['work_time'] = $work_time;
        $timeArr = [];
        for($i=1;$i<=7;$i++){
            $date = date("Y-m-d",strtotime("+".$i." day"));
            $timeArr[$i]['date'] = date("m-d",strtotime($date));
            $timeArr[$i]['week_name'] = get_week($date);
        }
        $data['timeArr'] = $timeArr;
        return ajax_return($data);
    }
}
